package com.redoor.app.stake.basicdata.controller;

import com.redoor.app.stake.basicdata.model.BaseSystemOperationLog;
import com.redoor.app.stake.basicdata.model.BussinessTypeEnum;
import com.redoor.app.stake.basicdata.model.controllerModel.BaseSystemOperationLogCriteria;
import com.redoor.app.stake.basicdata.service.BaseSystemOperationLogService;
import com.redoor.app.stake.common.model.Page;
import com.redoornetwork.framework.core.response.ResponseResult;
import com.redoornetwork.framework.core.response.ResultGenerator;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* Created by wangjunlei on 2018-03-08 17:30:08.
*/
@RestController
@RequestMapping("/base/system/operation/logs")
public class BaseSystemOperationLogController {

    @Autowired
    private BaseSystemOperationLogService baseSystemOperationLogService;

    @ApiOperation(value = "添加操作日志", notes = "添加操作日志")
    @PostMapping
    @ApiImplicitParams({
            @ApiImplicitParam(name = "web_operator_type", value = "操作对象类型", paramType = "query", dataType = "String", required = true, defaultValue = "20"),
            @ApiImplicitParam(name = "action_type", value = "动作类型", paramType = "query", dataType = "String", required = true, defaultValue = "1"),
            @ApiImplicitParam(name = "targetuuid", value = "对象id", paramType = "query", dataType = "String", required = false, defaultValue = ""),
            @ApiImplicitParam(name = "remark", value = "备注", paramType = "query", dataType = "String", required = false, defaultValue = ""),
    })
    public ResponseResult add(BussinessTypeEnum.WEB_OPERATOR_TYPE web_operator_type, BussinessTypeEnum.TAG_TYPE action_type, String targetuuid, String remark) {
        baseSystemOperationLogService.addSystemOperationLog(web_operator_type,action_type,targetuuid,remark,true);
        return ResultGenerator.generatorSuccess();
    }

    @GetMapping
    public ResponseResult list(BaseSystemOperationLogCriteria criteria) {
        List<BaseSystemOperationLog> list = baseSystemOperationLogService.qrySystemOperationLogByContion(criteria);
        int total = baseSystemOperationLogService.qrySystemOperationLogCnt(criteria);
        Page page = new Page();
        page.setTotal(total);
        page.setData(list);
        return ResultGenerator.generatorSuccess(page);
    }

}
